import { getPingCeValue, savePingCeValue, getAppPingCeValue } from  '../../../service/api';
import { myMessage } from '../../../utils/formatDataSource';
export default {
  namespace: 'pingce',

  state: {
    data: [],
    appData: [],
  },

  effects: {
    *getValue({ payload }, { call, put }) {
      const response = yield call(getPingCeValue, payload);
      yield put({
        type: 'r_getValue',
        payload: response,
      });
    },
    *save({ payload }, { call, put }) {
      const response = yield call(savePingCeValue, payload);
      yield put({
        type: 'r_save',
        payload: response,
      });
    },
    *getAppValue({ payload }, { call, put }) {
      const response = yield call(getAppPingCeValue, payload);
      yield put({
        type: 'r_getAppValue',
        payload: response,
      });
    },
  },

  reducers: {
    r_getValue(state, { payload }) {
      if (payload) {
        state.data = payload.data;
      }
      return {
        ...state,
      };
    },
    r_save(state, { payload }) {
      const { status } = payload;
      if (status === 0) {
        myMessage.success('保存成功', 2);
      } else {
        myMessage.error('保存失败', 2);
      }
      return {
        ...state,
      };
    },
    r_getAppValue(state, { payload }) {
      if (payload) {
        state.appData = payload.data;
      }
      return {
        ...state,
      };
    },
  },
};
